(async function () {
  const attributeName = api.originEntity.name;
  const taskNote = api.originEntity.getNote();
    
  if (attributeName === "dueDate") {
    if (taskNote.getParentNotes().some((m) => m.hasLabel("todoDone"))) {
        //taskNote.removeLabel("completedDate");
        //taskNote.removeLabel("spent");
        //taskNote.removeLabel("timeSpent");
        //taskNote.save();
        
        await taskReTodo(taskNote.noteId); 
               
    }  
    
    await taskUpdateTimeLeft(taskNote.noteId);
    
    return;
  }

  if (attributeName === "completedDate") {
    
    
    await taskComplete(taskNote.noteId);

    return;
  }
    
  if (attributeName === "addDescription") {
    if(api.originEntity.value === "true"){
        // api.log(taskNote.noteId);
        await descriptionLabel(taskNote.noteId);
    } else {
        taskNote.removeLabel("descriptionLabel"); 
    }

    return;
  }    
})();
